package com.save_file_for_mysql;

import java.io.*;

/**
 * @ClassName: FileUtilForMySQL
 * @Author: ZhangYue26
 * @Description: 获取文件流工具
 * @Date: 2020-08-11
 */
public class FileUtilForMySQL {
 
     // 读取本地图片获取输入流
     public static FileInputStream readImage(String path) throws IOException {
         return new FileInputStream(new File(path));
     }
 
     // 读取表中图片获取输出流
     public static void readBin2Image(InputStream in, String targetPath) {
         File file = new File(targetPath);
         FileOutputStream fos = null;
         try {
             fos = new FileOutputStream(file);
             int len = 0;
             byte[] buf = new byte[1024];
             while ((len = in.read(buf)) != -1) {
                 fos.write(buf, 0, len);
             }
             fos.flush();
         } catch (Exception e) {
             e.printStackTrace();
         } finally {
             if (null != fos) {
                 try {
                     fos.close();
                 } catch (IOException e) {
                     e.printStackTrace();
                 }
             }
         }
     }
}